﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Definition;
using Besture.Common.Helper;
using Besture.Common.Mail;
using Besture.Model;

namespace Besture.UI.Portal.FindUserPwd
{
    public partial class EmailFindOne : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 发送邮件验证码
        /// </summary>
        public void EmailFindPass()
        {
            string email = txtEmail.Text.Trim();
            UserBaseModel userBaseModel = new UserBaseDac().GetDataByUser(email);
            string emailTitle = XmlHelper.GetContentByNode(AppSettings.GetMsgPath(), Constants.EMAIL_FINDPASS_TITLE);
            string emailContant = XmlHelper.GetContentByNode(AppSettings.GetMsgPath(), Constants.EMAIL_FINDPASS_CONTENT);
            MailHelper.SendEmail(MailHelper.InitMailMessage(emailTitle, email, string.Format(emailContant,
                "http://" + Request.Url.Authority + "/Portal/FindUserPwd/EmailFindThree.aspx?user=" +
                EncryptHelper.Encrypt(userBaseModel.ID.ToString())), null));
        }


        protected void btnNext_Click(object sender, EventArgs e)
        {
            if (Session["CheckCode"] != null && txtVerificationCode.Text.ToLower() != Session["CheckCode"].ToString().ToLower())
            {
                FunHelper.Alert(Page, "验证码错误！");
                return;
            }

            UserBaseDac userBaseDac = new UserBaseDac();
            UserBaseModel userBaseModel = userBaseDac.GetDataByUser(txtEmail.Text.Trim());
            if (userBaseModel == null)
            {
                FunHelper.Alert(Page, "电子邮箱错误！");
                return;
            }
            EmailFindPass(); //发送邮件 
            Response.Redirect("EmailFindTwo.aspx?user=" + EncryptHelper.Encrypt(userBaseModel.ID.ToString()));
        }
    }
}